/**
 * 漏斗图数据格式化
 */
export const formatFunnel = (data) => {
    let legendData = []
    let seriesData = []
    if ('hallEnter' in data) { // 组队活跃
        legendData = ['匹配数据', '进入房间', '准备和开始游戏', '进入倒计时', '检测链接', '提交评价']
        seriesData = [
            [
                { value: 60, name: '匹配数据' },
                { value: 50, name: '进入房间' },
                { value: 40, name: '准备和开始游戏' },
                { value: 30, name: '进入倒计时' },
                { value: 20, name: '检测链接' },
                { value: 10, name: '提交评价' }
            ],
            [
                { value: data.matchClickTotal, name: '匹配数据' },
                { value: data.matchEnterTotal, name: '进入房间' },
                { value: data.clickPrepareAndStartGame, name: '准备和开始游戏' },
                { value: data.countDown, name: '进入倒计时' },
                { value: data.checkUrl, name: '检测链接' },
                { value: data.comment, name: '提交评价' }
            ]
        ]
    }
    if ('captainComment' in data) { // 队长活跃
        legendData = ['点击建房次数', '选择场次', '成功建房', '进入倒计时', '提交评价', '检测链接']
        seriesData = [
            [
                { value: 60, name: '点击建房次数' },
                { value: 50, name: '选择场次' },
                { value: 40, name: '成功建房' },
                { value: 30, name: '进入倒计时' },
                { value: 20, name: '检测链接' },
                { value: 10, name: '提交评价' }
            ],
            [
                { value: data.captainClickCreateRoomCount, name: '点击建房次数' },
                { value: data.captainSelectRoomTypeUserCount, name: '选择场次' },
                { value: data.captainCreateRoomSuccess, name: '成功建房' },
                { value: data.captainCountDown, name: '进入倒计时' },
                { value: data.captainCheckUrl, name: '检测链接' },
                { value: data.captainComment, name: '提交评价' }
            ]
        ]
    }
    if ('newAddCaptainComment' in data) { // 队长新增
        legendData = ['点击建房次数', '答完题用户', '通过模拟', '成功建房', '进入倒计时', '检测链接', '提交评价']
        seriesData = [
            [
                { value: 70, name: '点击建房次数' },
                { value: 60, name: '答完题用户' },
                { value: 50, name: '通过模拟' },
                { value: 40, name: '成功建房' },
                { value: 30, name: '进入倒计时' },
                { value: 20, name: '提交评价' },
                { value: 10, name: '检测链接' }
            ],
            [
                { value: data.newAddCaptainClickCreateRoomCount, name: '点击建房次数' },
                { value: data.newAddCaptainAnswerQuestion, name: '答完题用户' },
                { value: data.newAddCaptainCreateProcessRoom, name: '通过模拟' },
                { value: data.newAddCaptainCreateRoomSuccess, name: '成功建房' },
                { value: data.newAddCaptainCountDown, name: '进入倒计时' },
                { value: data.newAddCaptainComment, name: '提交评价' },
                { value: data.newAddCaptainCheckUrl, name: '检测链接' }
            ]
        ]
    }
    if ('totalFinishQuestion' in data) { // 队长累计
        legendData = ['答完题用户', '通过模拟', '成功建房', '成功开局', '提交评价']
        seriesData = [
            [
                { value: 50, name: '答完题用户' },
                { value: 40, name: '通过模拟' },
                { value: 30, name: '成功建房' },
                { value: 20, name: '成功开局' },
                { value: 10, name: '提交评价' }
            ],
            [
                { value: data.totalFinishQuestion, name: '答完题用户' },
                { value: data.totalSimulateCreateRoom, name: '通过模拟' },
                { value: data.totalCreateRoomSuccess, name: '成功建房' },
                { value: data.totalPlay, name: '成功开局' },
                { value: data.totalComment, name: '提交评价' }
            ]
        ]
    }
    if ('newAddActive' in data) { // 新增组队
        legendData = ['激活用户', '点击趣组队用户', '完善入队卡', '快速入队', '匹配进入房间',
        '点击队伍大厅', '从队伍大厅入房', '点击准备', '点击开始游戏', '进入倒计时', '检测链接', '结束评价']
        seriesData = [
            [
                // { value: 110, name: '激活用户' },
                // { value: 100, name: '点击趣组队用户' },
                // { value: 90, name: '完善入队卡' },
                // { value: 80, name: '快速入队' },
                // { value: 70, name: '匹配进入房间' },
                // { value: 60, name: '点击队伍大厅' },
                { value: 60, name: '匹配数据' },
                { value: 50, name: '进入房间' },
                { value: 40, name: '准备和开始游戏' },
                { value: 30, name: '进入倒计时' },
                { value: 20, name: '检测链接' },
                { value: 10, name: '结束评价' }
            ],
            [
                // { value: data.newAddActive, name: '激活用户' },
                // { value: data.newAddClickTeamButton, name: '点击趣组队用户' },
                // { value: data.newAddFirstEditCondition, name: '完善入队卡' },
                // { value: data.newAddClickQucikEnterRoom, name: '快速入队' },
                // { value: data.newAddMatchEnterRoom, name: '匹配进入房间' },
                // { value: data.newAddHallEnter, name: '点击队伍大厅' },
                { value: data.newAddMatchClickTotal, name: '匹配数据' },
                { value: data.newAddMatchEnterTotal, name: '进入房间' },
                // { value: data.newAddHallEnterRoom, name: '从队伍大厅入房' },
                { value: data.newAddClickPrepareAndStartGame, name: '准备和开始游戏' },
                { value: data.newAddCountDown, name: '进入倒计时' },
                { value: data.newAddCheckUrl, name: '检测链接' },
                { value: data.newAddComment, name: '结束评价' }
            ]
        ]
    }
    return { legendData, seriesData }
}

/**
 * 用户详情表格中提取时间，用于展示在excharts的X轴
 * tableData: 表格数据对象
 * key: 获取数据的字段名
 */
export const extractDataForEcharts = (tableData, key) => {
    let valueArr = []
    tableData.map(item => {
        valueArr.push(item[key])
    })
    return valueArr
}

/**
 * 获取X轴数据
 * data: 所有数据集合
 */
export const getEchartsSeries = (data, pageType) => {
    let seriesObj = {}
    let smooth = '1'
    let type = 'line'
    console.log('data', data)
    Object.keys(data[0]).map(item => {
        seriesObj[item] = []
        data.map(it => {
            seriesObj[item].push(it[item])
        })
    })
    if (pageType === 'legendary') {
        return [
            {
                name: '大神功能日活',
                data: seriesObj.teamRoomActiveCount,
                type,
                smooth
            },
            {
                name: '大神日活',
                data: seriesObj.teamActiveCount,
                type,
                smooth
            },
            {
                name: '创建房间',
                data: seriesObj.roomCount,
                type,
                smooth
            },
            {
                name: '有效房间',
                data: seriesObj.validRoomCount,
                type,
                smooth
            },
            {
                name: '付费成功次数',
                data: seriesObj.applySuccess,
                type,
                smooth
            },
            {
                name: '进入房间成员',
                data: seriesObj.enterRoomUser,
                type,
                smooth
            },
            {
                name: '付费用户',
                data: seriesObj.applyUser,
                type,
                smooth
            },
            {
                name: '接单大神',
                data: seriesObj.createOrderUser,
                type,
                smooth
            },
            {
                name: '对局数',
                data: seriesObj.createOrderCount,
                type,
                smooth
            },
            {
                name: '大神平均接单数',
                data: seriesObj.averageCreateOrderCount,
                type,
                smooth
            },
            {
                name: '付费用户平均付费数',
                data: seriesObj.averageApplyCount,
                type,
                smooth
            },
            {
                name: '大神邀请用户',
                data: seriesObj.dashenInvite,
                type,
                smooth
            },
            {
                name: '用户邀请用户',
                data: seriesObj.userInvite,
                type,
                smooth
            },
            {
                name: 'GMV',
                data: seriesObj.gmv,
                type,
                smooth
            }
        ]
    } else {
        return [
            {
                name: '日活',
                data: seriesObj.teamActiveCount,
                type,
                smooth
            },
            {
                name: '房间数',
                data: seriesObj.roomCount,
                type,
                smooth
            },
            {
                name: '有效房间',
                data: seriesObj.validRoomCount,
                type,
                smooth
            },
            {
                name: '对局',
                data: seriesObj.playGameCount,
                type,
                smooth
            },
            {
                name: '平均匹配时间(s)',
                data: seriesObj.matchAverageTime,
                type,
                smooth
            },
            {
                name: '补贴(元)',
                data: seriesObj.allowance,
                type,
                smooth
            },
            {
                name: '快速匹配pv',
                data: seriesObj.matchPV,
                type,
                smooth
            },
            {
                name: '快速匹配uv',
                data: seriesObj.matchUV,
                type,
                smooth
            },
            {
                name: '对局人数',
                data: seriesObj.playGameUserCount,
                type,
                smooth
            },
            {
                name: '组队超时',
                data: seriesObj.startUpOneHourRoomCount,
                type,
                smooth
            },
            {
                name: '匹配超时',
                data: seriesObj.matchRoomUpTime,
                type,
                smooth
            },
            {
                name: '邀请组队',
                data: seriesObj.inviteMatchUserCount,
                type,
                smooth
            },
            {
                name: '开局超过1小时',
                data: seriesObj.startGameUpTimeCount,
                type,
                smooth
            }
        ]
    }
}
